<?php

class NewsPeer extends BaseNewsPeer
{
	public static function getListByCategory($category_id,$limit=10) {
		$obj = DbFinder::from('News')
						->with('I18n')
						->where('NewsCategoryId',$category_id)
						->where('IsPublic',1)
						->orderBy('CreatedAt', 'desc')
						->find($limit);
		return $obj;
	}
	
	public static function getListByCategoryWithPagination($category_id,$start = 1,$limit = 10) {
		return DbFinder::from('News')
						->with('I18n')
						->where('NewsCategoryId',$category_id)
						->where('IsPublic',1)
						->orderBy('CreatedAt', 'desc')
						//->useCache(sfConfig::get('sf_cache'), 200)
						->paginate($start, $limit);
	}
	
	public static function getNewsDetail($news_id)
	{
		$a = DbFinder::from('News')
				->with('I18n')
				->where('News.Id',$news_id)
				->where('IsPublic',1)
				->find(1);
		return $a[0];
	}
	
	public static function getListRelated($news_id,$category_id,$limit=5) {
		$obj = DbFinder::from('News')
						->with('I18n')
						->where('NewsCategoryId',$category_id)
						->where('News.Id','<',$news_id)
						->where('IsPublic',1)
						->orderBy('CreatedAt', 'desc')
						->find($limit);
		return $obj;
	}
	
}
